﻿@page
@model IndexModel
@{
    ViewData["Title"] = "Background Tasks Sample";
}

<h1>@ViewData["Title"]</h1>

<p>Run the app locally and monitor console output to track background service processing.</p>

<div class="row">
    <div class="col-md-8">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h2 class="panel-title">Timed Hosted Service</h2>
            </div>
            <div class="panel-body">
                <p>Watch the console to see the timed background task running every 5 seconds.</p>
            </div>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-8">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h2 class="panel-title">Scoped Hosted Service</h2>
            </div>
            <div class="panel-body">
                <p>Watch the console to see the scoped background task running once when the app starts.</p>
            </div>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-8">
        <form method="post">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h2 class="panel-title">Queued Hosted Service</h2>
                </div>
                <div class="panel-body">
                    <p>
                        Select the <b>Add Task</b> button a few times to add a few tasks to the queue. Each task is created with a unique GUID. The tasks are run sequentially (one at a time). Watch the console to monitor each task as it completes in 15 seconds.
                    </p>
                    <div class="form-group">
                        <button type="submit" asp-page-handler="AddTask" class="btn btn-default">Add Task</button>
                    </div>
                    <h3>Database Messages</h3>
                    <p>After selecting the <b>Add Task</b> button a few times. Refresh the page in the browser every few seconds. As the tasks are running, task status messages are saved into the database. The page shows the current contents of the database on each page refresh.</p>
                    <ol>
                        @foreach (var message in Model.Messages)
                        {
                            <li>
                                @message.Text
                            </li>
                        }
                    </ol>
                </div>
            </div>
        </form>
    </div>
</div>
